from django.db import models


# Create your models here.
class Warehouse(models.Model):
    ware_id = models.CharField(primary_key=True, max_length=32)
    name = models.CharField(max_length=30, blank=True, null=True)
    city = models.CharField(max_length=20, blank=True, null=True)
    address = models.CharField(max_length=50, blank=True, null=True)
    latitude = models.CharField(max_length=30, blank=True, null=True)
    longitude = models.CharField(max_length=30, blank=True, null=True)
    area = models.CharField(max_length=20, blank=True, null=True)
    staff_name = models.CharField(max_length=10, blank=True, null=True)
    overview = models.TextField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'warehouse'

class Goods(models.Model):
    goods_id = models.CharField(primary_key=True, max_length=32)
    num = models.CharField(max_length=10, blank=True, null=True)
    name = models.CharField(max_length=30, blank=True, null=True)
    kind = models.CharField(max_length=30, blank=True, null=True)
    cost = models.FloatField(blank=True, null=True)
    retail = models.FloatField(blank=True, null=True)
    img = models.CharField(max_length=200, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'goods'

class Stock(models.Model):
    stock_id = models.CharField(primary_key=True, max_length=32)
    ware = models.ForeignKey(Warehouse, on_delete=models.DO_NOTHING, db_column='ware_id', max_length=32, blank=True, null=True,
                             verbose_name='仓库编号')
    num = models.CharField(max_length=10, blank=True, null=True, verbose_name='库管编号')
    city = models.CharField(max_length=20, blank=True, null=True)
    kind = models.CharField(max_length=30, blank=True, null=True)
    count = models.IntegerField(blank=True, null=True)
    detail = models.CharField(max_length=32, blank=True, null=True)
    goods = models.ForeignKey(Goods, on_delete=models.DO_NOTHING, blank=True, null=True)
    location = models.CharField(max_length=15, blank=True, null=True)

    def __str__(self):
        return '{}.{}'.format(self.stock_id, self.ware_id)

    class Meta:
        managed = False
        db_table = 'stock'

